
const app = getApp();
var util = require('../../utils/util.js');  
var OrderListUrl="userOrderApi/selectOrderList";

var Orderstatus;
var OrderList;
var Ordertime = [];
Page({
  data: {
    OrderList:{},
    Orderstatus:""
  },

  onLoad: function (options) {
    wx.showLoading();
    var that= this;

    wx.request({
      url: app.globalData.requestUrl + OrderListUrl,
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      data: {//这里写你要请求的参数
        userID: app.globalData.userId,
      },

      success: function (res) {
        wx.hideLoading();
        //将获取到的json数据，
        console.log(res);//打印日志


        that.setData({
          OrderList: res.data.list,//实例化第一次传过来的数据
        });

        var list = that.data.OrderList;
        for (var i = 0; i < list.length; i++) {
          var status = list[i].status;
          var rateStatus = list[i].rateStatus;

          if (status == "C125001") {
            Orderstatus = "待发货";
          } else if (status == "C125003") {
            Orderstatus = "待收货";
          } else if (status == "C125005") {
            Orderstatus = "待付款";
          } else if (status == "C125004" && rateStatus == 0) {
            Orderstatus = "待评价";
          } else if (status == "C125004" && rateStatus == 1) {
            Orderstatus = "订单完成";
          } else if (status == "C125002" || status == "C125006") {
            Orderstatus = "取消订单";
          } else if (status == "C125007") {
            Orderstatus = "退款成功";
          } else if (status == "C125008") {
            Orderstatus = "退款处理中";
          } else {

          };
          var tempstatus = 'OrderList[' + i + '].Orderstatus';
          that.setData({ //二次实例化
            [tempstatus]: Orderstatus
          })

        };

        for (let i = 0; i < list.length; i++) {
          let time = util.formatTime(new Date(list[i].createTime));
          let temp = 'OrderList[' + i + '].time';
          that.setData({ //二次实例化
            [temp]: time
          })
        };
      }
    })

  },
  toOrderdetails:function(e){
console.log(e)
    wx.navigateTo({
      url: '/pages/order-details/order-details?id=' + e.currentTarget.dataset.id,
    })
  },
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },


})